package com.fwx.controller;

import com.fwx.entity.Emp;
import com.fwx.service.EmpService;
import com.fwx.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: springBoot06
 * @description:
 * @author: 范文轩
 * @create: 2024-07-15 08:52
 **/

@RestController
@RequestMapping("/emp")
@Api(value = "员工管理")
public class EmpController {
    
    @Autowired
    private EmpService empService;
    
    // 添加员工
    @ApiOperation(value = "添加员工")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "emp",value = "员工实体",required = true,dataType = "Emp")
    )
    @PostMapping("/insert")
    public R insert(@RequestBody Emp emp){
        return empService.insert(emp);
    }
    
    // 通过员工编号修改员工信息
    @ApiOperation(value = "通过员工编号修改员工信息")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "emp",value = "员工实体",required = true,dataType = "Emp")
    )
    @PutMapping("/updateById")
    public R updateById(@RequestBody Emp emp){
        return empService.updateById(emp);
    }
    
    // 通过员工编号删除
    @ApiOperation(value = "通过员工编号删除")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "empno",value = "员工编号",required = true,dataType = "int")
    )
    @DeleteMapping("/deleteById")
    public R deleteById(Integer empno){
        return empService.deleteById(empno);
    }
    
    // 分页查询全部员工信息
    @ApiOperation(value = "分页查询全部员工信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页数", required = true, dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页条数", required = true, dataType = "int")
    })
    @GetMapping("/selectAll")
    public R selectAll(Integer current,Integer size){
        return empService.selectAll(current,size);
    }
    
    // 根据员工编号查询
    @ApiOperation(value = "根据员工编号查询")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "empno",value = "员工编号",required = true,dataType = "int")
    )
    @GetMapping("/selectByEmpNo")
    public R selectById(Integer empno){
        return empService.selectByEmpNo(empno);
    }
    
}
